{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "source": [
    "import math\r\n",
    "print(math.ceil(3.1))\r\n",
    "print(math.floor(4.6))\r\n",
    "print(math.fabs(-123.456))\r\n",
    "print(math.sqrt(36))\r\n",
    "print(math.exp(1))\r\n",
    "print(math.log2(4))"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "4\n",
      "4\n",
      "123.456\n",
      "6.0\n",
      "2.718281828459045\n",
      "2.0\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "source": [
    "import random\r\n",
    "print(random.random())\r\n",
    "print(random.randint(1,10))"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "0.532100387021133\n",
      "1\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "source": [
    "print('单引号')\r\n",
    "print(\"双引号\")\r\n",
    "print('''三引号''')\r\n",
    "str1 = '''\r\n",
    "<html>\r\n",
    "    <head>\r\n",
    "        <title>我是一只羊</title>\r\n",
    "        <style>\r\n",
    "            div {\r\n",
    "                width: 100px;\r\n",
    "                height: 100px;\r\n",
    "                background-color: green;\r\n",
    "            }\r\n",
    "        </style>\r\n",
    "    </head>\r\n",
    "    <body>\r\n",
    "        <div>这里是我的地盘！</div>\r\n",
    "    </body>\r\n",
    "</html>\r\n",
    "'''\r\n",
    "print(str1)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "单引号\n",
      "双引号\n",
      "三引号\n",
      "\n",
      "<html>\n",
      "    <head>\n",
      "        <title>我是一只羊</title>\n",
      "        <style>\n",
      "            div {\n",
      "                width: 100px;\n",
      "                height: 100px;\n",
      "                background-color: green;\n",
      "            }\n",
      "        </style>\n",
      "    </head>\n",
      "    <body>\n",
      "        <div>这里是我的地盘！</div>\n",
      "    </body>\n",
      "</html>\n",
      "\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "source": [
    "a = \"20210830\"\r\n",
    "b = \"weekday01\"\r\n",
    "c = \"hi\"\r\n",
    "print(a+b)\r\n",
    "print(c*3)\r\n",
    "print(a[5])\r\n",
    "print(a[2:8])\r\n",
    "print('e' in b)\r\n",
    "print('e' not in b)\r\n",
    "print('-'.join(a))"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "20210830weekday01\n",
      "hihihi\n",
      "8\n",
      "210830\n",
      "True\n",
      "False\n",
      "2-0-2-1-0-8-3-0\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "source": [
    "print(\"这里有一个洞！——>\\t<——请小心！\")\r\n",
    "print(\"第一行\\n第二行\")\r\n",
    "print(\"\\\"羊大仙\\\"——yyz\")"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "这里有一个洞！——>\t<——请小心！\n",
      "第一行\n",
      "第二行\n",
      "\"羊大仙\"——yyz\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "source": [
    "list01 = [\"杨雨卓\",\"蔡佳桐\",\"陈政光\",\"高裕景新\",\"柯瑞\",\"聂大涛\"]\r\n",
    "print(type(list01))\r\n",
    "print(list01[0])\r\n",
    "print(list01[-len(list01)])\r\n",
    "print(list01[-1])\r\n",
    "print(list01[len(list01)-1])"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "<class 'list'>\n",
      "杨雨卓\n",
      "杨雨卓\n",
      "聂大涛\n",
      "聂大涛\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "source": [
    "list02 = [\"孟老师\", \"孙老师\", \"冷老师\", \"刘老师\"]\r\n",
    "for i in list02:\r\n",
    "    print(i)\r\n",
    "for i in list02:\r\n",
    "    if i == \"孙老师\":\r\n",
    "        print(\"该元素是孙老师！\")\r\n",
    "    else:\r\n",
    "        print(\"该元素不是孙老师！\")\r\n",
    "if \"孟老师\" in list02:\r\n",
    "    print(\"存在孟老师！\")\r\n",
    "else:\r\n",
    "    print(\"没有查找到孟老师！\")"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "孟老师\n",
      "孙老师\n",
      "冷老师\n",
      "刘老师\n",
      "该元素不是孙老师！\n",
      "该元素是孙老师！\n",
      "该元素不是孙老师！\n",
      "该元素不是孙老师！\n",
      "存在孟老师！\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "source": [
    "emptylist = []\r\n",
    "emptylist.append(\"计算7班\")\r\n",
    "print(emptylist)\r\n",
    "member = [\"男生\", \"女生\"]\r\n",
    "emptylist.extend(member)\r\n",
    "print(emptylist)\r\n",
    "emptylist.insert(0, \"19级\")\r\n",
    "print(emptylist)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "['计算7班']\n",
      "['计算7班', '男生', '女生']\n",
      "['19级', '计算7班', '男生', '女生']\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "source": [
    "color = ['red', 'green', 'blue','白色', 'orange', '黑色']\r\n",
    "print(color)\r\n",
    "color[-1] = 'black'\r\n",
    "print(color)\r\n",
    "for i in range(len(color)):\r\n",
    "    if '白色' in color[i]:\r\n",
    "        color[i] = 'white'\r\n",
    "print(color)\r\n"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "['red', 'green', 'blue', '白色', 'orange', '黑色']\n",
      "['red', 'green', 'blue', '白色', 'orange', 'black']\n",
      "['red', 'green', 'blue', 'white', 'orange', 'black']\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "source": [
    "color = ['red', 'green', 'blue', 'white', 'orange', 'black']\r\n",
    "del color[0]\r\n",
    "print(color)\r\n",
    "color.remove('green')\r\n",
    "print(color)\r\n",
    "color.pop(0)\r\n",
    "print(color)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "['green', 'blue', 'white', 'orange', 'black']\n",
      "['blue', 'white', 'orange', 'black']\n",
      "['white', 'orange', 'black']\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "source": [
    "schoolclassmates = [\"杨雨卓\",\"蔡佳桐\",\"陈政光\",\"高裕景新\",\"柯瑞\",\"聂大涛\"]\r\n",
    "print(schoolclassmates[2:5])\r\n",
    "print(schoolclassmates[-1:])\r\n",
    "print(schoolclassmates[-3:-1])\r\n",
    "print(schoolclassmates[-5:-1:2])\r\n",
    "print(schoolclassmates[::2])"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "['陈政光', '高裕景新', '柯瑞']\n",
      "['聂大涛']\n",
      "['高裕景新', '柯瑞']\n",
      "['蔡佳桐', '高裕景新']\n",
      "['杨雨卓', '陈政光', '柯瑞']\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "source": [
    "import math\r\n",
    "numlist01 = []\r\n",
    "for i in range(10):\r\n",
    "    ran = random.randint(1,100)\r\n",
    "    if ran not in numlist01:\r\n",
    "        numlist01.append(ran)\r\n",
    "print(numlist01)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[8, 100, 72, 44, 20, 53, 82, 96, 6, 32]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "source": [
    "import random\r\n",
    "numlist02 = []\r\n",
    "i = 0;\r\n",
    "while i < 10:\r\n",
    "    ran = random.randint(1,100)\r\n",
    "    if ran not in numlist02:\r\n",
    "        numlist02.append(ran)\r\n",
    "        i+=1\r\n",
    "print(numlist02)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[5, 96, 36, 61, 54, 82, 22, 35, 17, 58]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "source": [
    "lis = [1,7,5]\r\n",
    "print(sorted(lis))\r\n",
    "print(sorted(lis,reverse=True))"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[1, 5, 7]\n",
      "[7, 5, 1]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "source": [
    "tuple1 = ()\r\n",
    "print(tuple1)\r\n",
    "print(type(tuple1))\r\n",
    "tuple2 = (\"hello\")\r\n",
    "print(tuple2)\r\n",
    "print(type(tuple2))\r\n",
    "tuple3 = (\"hello\",)\r\n",
    "print(tuple3)\r\n",
    "print(type(tuple3))"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "()\n",
      "<class 'tuple'>\n",
      "hello\n",
      "<class 'str'>\n",
      "('hello',)\n",
      "<class 'tuple'>\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "source": [
    "listtext = [123,456,789,321,654,987,100,200,300,400,500]\r\n",
    "tupletext = (listtext)\r\n",
    "print(tupletext)\r\n",
    "print(tupletext[0])\r\n",
    "print(tupletext[-1])\r\n",
    "print(tupletext[1:-3])\r\n",
    "print(tupletext[::-1])"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[123, 456, 789, 321, 654, 987, 100, 200, 300, 400, 500]\n",
      "123\n",
      "500\n",
      "[456, 789, 321, 654, 987, 100, 200]\n",
      "[500, 400, 300, 200, 100, 987, 654, 321, 789, 456, 123]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "source": [
    "t1 = (1,2,3)+(4,5,6)\r\n",
    "print(t1)\r\n",
    "t2 = (0,1)*2\r\n",
    "print(t2)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "(1, 2, 3, 4, 5, 6)\n",
      "(0, 1, 0, 1)\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "source": [
    "lis01 = [123,456,789,120,132,143,154,165,176]\r\n",
    "tuple03 = (lis01)\r\n",
    "print(tuple03)\r\n",
    "print(max(tuple03))\r\n",
    "print(min(tuple03))\r\n",
    "print(sum(tuple03))\r\n",
    "print(len(tuple03))"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[123, 456, 789, 120, 132, 143, 154, 165, 176]\n",
      "789\n",
      "120\n",
      "2258\n",
      "9\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "source": [
    "dict1 = {}\r\n",
    "print(dict1)\r\n",
    "print(type(dict1))\r\n",
    "dict2 = {'name':'yyz','weight':'45','age':25}\r\n",
    "print(dict2)\r\n",
    "print(dict2[\"name\"])"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "{}\n",
      "<class 'dict'>\n",
      "{'name': 'yyz', 'weight': '45', 'age': 25}\n",
      "yyz\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "source": [
    "dict3 = dict([('name','yyz'),('age','22'),('sex','man')])\r\n",
    "print(dict3)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "{'name': 'yyz', 'age': '22', 'sex': 'man'}\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "source": [
    "dict4 = {}\r\n",
    "dict4[\"name\"] = 'yyz'\r\n",
    "dict4[\"age\"] = '22'\r\n",
    "print(dict4)\r\n",
    "dict4[\"age\"] = '23'\r\n",
    "print(dict4)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "{'name': 'yyz', 'age': '22'}\n",
      "{'name': 'yyz', 'age': '23'}\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "source": [
    "dict5 = {'yyz':27,'cjt':2,'czg':5,'gyjx':7,'kr':12}\r\n",
    "print(dict5.items())\r\n",
    "for key,value in dict5.items():\r\n",
    "    if value > 10:\r\n",
    "        print(key)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "dict_items([('yyz', 27), ('cjt', 2), ('czg', 5), ('gyjx', 7), ('kr', 12)])\n",
      "yyz\n",
      "kr\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "source": [
    "dict5 = {'yyz':27,'cjt':2,'czg':5,'gyjx':7,'kr':12}\r\n",
    "result = dict5.values()\r\n",
    "print(result)\r\n",
    "name = dict5.keys()\r\n",
    "print(name)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "dict_values([27, 2, 5, 7, 12])\n",
      "dict_keys(['yyz', 'cjt', 'czg', 'gyjx', 'kr'])\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "source": [
    "dict6 = {'yyz':22,'cjt':22,'czg':21,'gyjx':20,'kr':24}\r\n",
    "age = dict6.values()\r\n",
    "total = sum(age)\r\n",
    "avg = total/len(age)\r\n",
    "print(avg)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "21.8\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "source": [
    "dict6 = {'yyz':22,'cjt':22,'czg':21,'gyjx':20,'kr':24}\r\n",
    "print(dict6['yyz'])\r\n",
    "# print(dict6['mxf'])\r\n",
    "print(dict6.get('mxf'))\r\n",
    "print(dict6.get('mxf',40))"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "22\n",
      "None\n",
      "40\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "source": [
    "dict6 = {'yyz':22,'cjt':22,'czg':21,'gyjx':20,'kr':24}\r\n",
    "del dict6['kr']\r\n",
    "print(dict6)\r\n",
    "result = dict6.pop('gyjx')\r\n",
    "print(result)\r\n",
    "print(dict6)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "{'yyz': 22, 'cjt': 22, 'czg': 21, 'gyjx': 20}\n",
      "20\n",
      "{'yyz': 22, 'cjt': 22, 'czg': 21}\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "source": [
    "class Animal:\r\n",
    "\r\n",
    "    def __init__(self,name):\r\n",
    "        self.name = name\r\n",
    "        print('动物名称实例化')\r\n",
    "    def eat(self):\r\n",
    "        print(self.name+'要吃东西了！')\r\n",
    "    def drink(self):\r\n",
    "        print(self.name+'要喝水了！')\r\n",
    "\r\n",
    "cat = Animal('xiaohuamao')\r\n",
    "print(cat.name)\r\n",
    "cat.eat()\r\n",
    "cat.drink()"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "动物名称实例化\n",
      "xiaohuamao\n",
      "xiaohuamao要吃东西了！\n",
      "xiaohuamao要喝水了！\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "source": [
    "class Person:\r\n",
    "    def __init__(self,name):\r\n",
    "        self.name = name\r\n",
    "        print('调用父类构造函数')\r\n",
    "    def eat(self):\r\n",
    "        print('调用父类方法')\r\n",
    "class Student(Person):\r\n",
    "    def __init__(self):\r\n",
    "        print('调用子类构造函数')\r\n",
    "    def study(self):\r\n",
    "        print('调用父类方法')\r\n",
    "s = Student()\r\n",
    "s.study()\r\n",
    "s.eat()"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "调用子类构造函数\n",
      "调用父类方法\n",
      "调用父类方法\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "source": [
    "import json\r\n",
    "data = [{'b':2,'d':4,'a':1,'c':3,'e':5}]\r\n",
    "json = json.dumps(data)\r\n",
    "print(json)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "[{\"b\": 2, \"d\": 4, \"a\": 1, \"c\": 3, \"e\": 5}]\n"
     ]
    }
   ],
   "metadata": {}
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "source": [
    "import json\r\n",
    "jsonData = '{\"a\":1,\"b\":2,\"c\":3,\"d\":4,\"e\":5}'\r\n",
    "text = json.loads(jsonData)  #将string转换为dict\r\n",
    "print(text)"
   ],
   "outputs": [
    {
     "output_type": "stream",
     "name": "stdout",
     "text": [
      "{'a': 1, 'b': 2, 'c': 3, 'd': 4, 'e': 5}\n"
     ]
    }
   ],
   "metadata": {}
  }
 ],
 "metadata": {
  "orig_nbformat": 4,
  "language_info": {
   "name": "python",
   "version": "3.9.6",
   "mimetype": "text/x-python",
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "pygments_lexer": "ipython3",
   "nbconvert_exporter": "python",
   "file_extension": ".py"
  },
  "kernelspec": {
   "name": "python3",
   "display_name": "Python 3.9.6 64-bit"
  },
  "interpreter": {
   "hash": "b23ed511805502d1f463bd89c50b4ebd8bbef08b00bcefbe7d2d24d807191004"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}